package com.pdf.pdfserver.util;

import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Font;
import com.itextpdf.text.pdf.BaseFont;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

/**
 * @Author songfz
 * @Description PDF文档数据编码
 * @Date 2022/1/5
 */
public class PdfConvertUtil {

    private static  Logger LOG = LoggerFactory.getLogger(PdfConvertUtil.class);
    /**
     * 设置中文
     *
     * @return Font
     */
    public static Font setChineseFont() {

        Font fontChinese = null;
        try {
            fontChinese = new Font( baseFont(), 12, Font.NORMAL);
        } catch (DocumentException|IOException e) {
           LOG.error(e.getMessage(),e);
        }
        return fontChinese;
    }


    public static BaseFont baseFont() throws IOException, DocumentException {
        String realpath = "simsun.ttf";
        BaseFont bfChinese = BaseFont.createFont(realpath,BaseFont.IDENTITY_H,BaseFont.EMBEDDED);
//        return BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
        return bfChinese;
    }
}
